package com.visec.hdy.hadoop.context;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * 图片读取上下文
 * 
 * @author hdy
 *
 */
public class ImageReadContextImpl extends FileReadContextImpl {

	public ImageReadContextImpl(String nameSpace, long count) {
		super(nameSpace, count);
	}

	@Override
	public List<File> sortFiles(List<File> files) {
		this.files = new ArrayList<>();
		Pattern p = Pattern.compile("^.*\\.(jpg|jpeg|png|gif)$");
		files.stream().sorted((a, b) -> a.isDirectory() ? 1 : -1).filter(a -> p.matcher(a.getName()).matches())
				.forEach(this.files::add);
		return this.files;
	}

}
